import React from 'react'
import {Breadcrumb} from 'antd'
import {Link,useLocation} from 'react-router-dom'
import menus from '@/router/menus'

// breadcurmNameMap = {
//  banner:'轮播图管理',
//  banner/home:'首页轮播图'
//  banner/active:'活动页轮播图',
//  banner/add:'添加轮播图'
//}
const breadcrumbNameMap = {};
const getBreadcrumbData = menus => {
  menus.forEach(item=>{
    if(item.children){
      breadcrumbNameMap[item.key] = item.label
      getBreadcrumbData(item.children)
    }else{
      breadcrumbNameMap[item.key] = item.label
    }
  })
}
getBreadcrumbData(menus)

export default function AppBreadcrumb() {
  const location = useLocation();
  const pathSnippets = location.pathname.split('/').filter((i) => i);
  const extraBreadcrumbItems = pathSnippets.map((_, index) => {
    const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
    return (
      <Breadcrumb.Item key={url}>
        <Link to={url}>{breadcrumbNameMap[url]}</Link>
      </Breadcrumb.Item>
    );
  });
  const breadcrumbItems = [
    location.pathname === '/' ? null :
    <Breadcrumb.Item key="home">
      <Link to="/">首页</Link>
    </Breadcrumb.Item>,
  ].concat(extraBreadcrumbItems);
  return (
    <div className="demo" style={{display:'flex',alignItems:'center'}}>
      <Breadcrumb>{breadcrumbItems}</Breadcrumb>
    </div>
  )
}
